/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package manufacturerbeans;

import java.util.List;
import javax.faces.model.ListDataModel;
import org.primefaces.model.SelectableDataModel;

/**
 *
 * @author Ara Yeritsian
 */
public class BatchDataModel extends ListDataModel<Batch> implements SelectableDataModel<Batch> {

    public BatchDataModel() {
    }

    public BatchDataModel(List<Batch> data) {
        super(data);
    }

    @Override
    public Batch getRowData(String rowKey) {
        //In a real app, a more efficient way like a query by rowKey should be implemented to deal with huge data  

        List<Batch> Batchs = (List<Batch>) getWrappedData();

        for (Batch batch : Batchs) {
            if (batch.getName().equals(rowKey)) {
                return batch;
            }
        }

        return null;
    }

    @Override
    public Object getRowKey(Batch batch) {
        return batch.getName();
    }
}
